package volatileDemo;

/**
 * Created by 5406160@qq.com on LiBoWen 李博闻.
 *
 * @ClassName : VolatileDemo
 * @Author : 54061
 * @Date: 2022/2/16 20:11
 */
public class VolatileDemo {
    public static void main(String[] args) {
        //创建小刚和小红线程
        MyThread1 小红 = new MyThread1();
        MyThread2 小刚 = new MyThread2();

        小红.start();
        小刚.start();
    }
}
//事物描述类
class Money{
    //public static int money = 100000;
    //此变量被标记为不稳定的变量 线程优先去内存中寻找值
    public static volatile int money = 100000;

}
//线程1:小红
class MyThread1 extends Thread{
    @Override
    public void run() {
        while (Money.money ==100000){

        }
        System.out.println("结婚基金已经不是十万了");
    }
}
//线程2 : 小刚
class MyThread2 extends Thread{
    @Override
    public void run() {
        try {
            Thread.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        Money.money = 90000;
    }
}